package com.ebs.md.fxmonitor.marketmonitor.config.esper;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/config/esper/CCCListenerToEsper.java $
 *  $Revision: #1 $  $Change: 115343 $  $DateTime: 2012/10/03 09:41:26 $  $Author: Arik.Sher $
 */

import java.util.Set;

import org.springframework.util.Assert;

import com.ebs.md.container.esper.AlertGroup;
import com.ebs.md.container.esper.IEsperAdminAccessor;
import com.ebsdr.fsp.ccc.client.IAppConfigurationEventListener;
import com.ebsdr.fsp.ccc.client.events.IAppConfigurationEvent;
import com.espertech.esper.client.EPAdministrator;

/**
 * 
 * listening to CCC major change, and when it comes refreshing the EsperStatements
 */
public class CCCListenerToEsper
implements   IAppConfigurationEventListener 
{
	protected IEsperAdminAccessor esperAdminAccessor;
	protected Set<AlertGroup>     alertGroups;
	
	public void init() {
		Assert.notNull(esperAdminAccessor, "'esperAdminAccessor' cannot be null");
		Assert.notEmpty(alertGroups,       "'alertGroups' should not be empty");
	}

	public void setEsperAdminAccessor(IEsperAdminAccessor esperAdminAccessor) {
		this.esperAdminAccessor = esperAdminAccessor;
	}

	public void setAlertGroups(Set<AlertGroup> alertGroups) {
		this.alertGroups = alertGroups;
	}

	protected void refreshAlertGroups() {
		EPAdministrator epAdministrator = esperAdminAccessor.getEPAdministrator();
		
		for ( AlertGroup curr : alertGroups ) {
			curr.prepare(epAdministrator);
		}
	}
	
	@Override
	public void handleConfigurationEvent(IAppConfigurationEvent iappconfigurationevent) {
		refreshAlertGroups();
	}

}
